nums = [1,2,14,23,15,11,13,36,24,26]
for(i = 0;i < nums.length;i++){
    let flag = true
    for(j = 1;j < nums.length - i;j++){
        if(nums[j - 1] > nums[j]){
            [nums[j - 1],nums[j]] = [nums[j],nums[j - 1]]
            flag = false
        }
    }
    if(flag){
        break
    }
}
console.log(nums)


nums = [1,2,14,23,15,11,13,36,24,26]
for(i = 0;i < nums.length - 1;i++){
    //let minindex = i
    for(j = i;j < nums.length;j++){
        if(nums[j] < nums[i]){
            //minindex = j
            [nums[i],nums[j]] = [nums[j],nums[i]]
            flag = false
        }
    }
}
console.log(nums)


nums = [1,2,14,23,15,11,13,36,24,25]
for(i = 1;i < nums.length;i++){
    for(j = i;j >= 0;j--){
        if(nums[j] < nums[j - 1]){
            [nums[j],nums[j - 1]] = [nums[j - 1],nums[j]]
        }else{
            break
        }
    }
}
console.log(nums)

nums = [1,2,14,23,15,11,13,36,24,25]
for(i = 1;i < nums.length;i++){
    let key = nums[i]
    let left = 0
    let right = i - 1
    while(left <= right){
        let mid = Math.floor(left + (right -left) / 2)
        if(nums[mid] > nums[i]){
            right = mid - 1
        }else{
            left = mid + 1
        }
    }
    for(j = i - 1;j >= left;j--){
        nums[j + 1] = nums[j]
    }
    nums[left] = key
}
console.log(nums)


// console.log(nums.splice(0,1))
nums = [1,2,14,23,15,11,13,36,24,26]
var sort = function(nums){
    if(nums.length <= 1){
        return nums
    }
    let basis = nums.splice(0,1)
    let left = []
    let right = []
    for(i = 0;i < nums.length;i++){
        if(basis[0] > nums[i]){
            left.push(nums[i])
        }else{
            right.push(nums[i])
        }
    }
    return sort(left).concat(basis,sort(right))
}
console.log(sort(nums))
// ip = "1:1:01:1:"
// str = ip.split(":")
// console.log(Number("1e1").toString() === "1e1")


function shellSort(nums) {
    var len = nums.length,
        temp,
        gap = 1;
    while(gap < len/3) {          //动态定义间隔序列
        gap =gap*3+1;
    }
    for (gap; gap > 0; gap = Math.floor(gap/3)) {
        for (var i = gap; i < len; i++) {
            temp = nums[i];
            for (var j = i-gap; j >= 0 && nums[j] > temp; j-=gap) {
                nums[j+gap] = nums[j];
            }
            nums[j+gap] = temp;
        }
    }
    return nums;
}
nums = [1,2,14,23,15,11,13,36,24,26]
console.log(shellSort(nums))